home *** CD-ROM | disk | FTP | other *** search
- /* PROGRAM CPROG2.CPP - Ctrl+F9 compiles and runs it */
-
- #include <stdio.h>
- #include <conio.h>
-
- /*--------------------------------------------------------------+
- | Definition of a function called pause() |
- | Pause() prints "Press a key to continue" then waits for a key |
- | to be pressed. The voids are explained in the article. |
- +--------------------------------------------------------------*/
- void pause(void)
- {
- printf("\nPress a key to continue...\n");
- while( kbhit() == 0 )
- ;
- getch();
- }
- /*-------------------------------------------------------------+
- | Note to experienced C/C++ programmers: yes, I know about |
- | while( !kbhit() ); and (void)getch(); - please don't |
- | write in. These programs are only illustrative, not part of |
- | a real project. They have to be clear and explainable within |
- | the scope of the article. |
- +-------------------------------------------------------------*/
-
- /*------------------------------------------------------------+
- | Program execution starts here in the function called main() |
- +------------------------------------------------------------*/
- main()
- {
-
- clrscr(); // Clears the screen. Header file is CONIO.H
-
- printf("I'm about to call the function Pause()\n");
-
- pause();
- /*------------------------------------------------------------+
- | Once Pause() has been defined, it can be used like a new |
- | command, although function calls are not commands as such - |
- | no function is part of the of the C++ language although the |
- | behaviour of the common ones have been formally defined by |
- | by the American National Standards Institute (ANSI). |
- +------------------------------------------------------------*/
-
- printf("\nDone it. Now let's do it again.\n");
- pause();
- }
- /*---------------------------------------------------------------------+
- | Program execution still ends here. Other functions only get executed |
- | if called from Main(), or called from a function that itself is |
- | called from Main(), or called from a function that is called from |
- | a function that is called from... etc etc |
- +---------------------------------------------------------------------*/
-